<?php

/*
 * File: template.inc.php
 * Descrizione: Classe per l'implementazione dei template.
*/
class template {

	var $code; // Contenitore del template

	// Costruttore della classe
	function __construct($file) {
		$this->code = file_get_contents($file);
	}

	// Sostituisce le tag speciali con i valori associati contenuti nell'array associativo $tags
	function replace($tags) {
		foreach($tags as $key => $value) {
			$this->code = str_replace("<$".$key."$>", $value, $this->code);
		}
	}

	// Restituisce il contenitore del template
	function show() {
		return $this->code;
	}

	// Distruttore della classe
	function __destruct() {
		unset($code);
	}

}
// Funzione di logging
function log_action($log_type, $log_size, $log_msg, $log_target, $user_id){
$query = "INSERT INTO logs (log_id, log_type, log_date, log_size, log_msg, log_target, user_id) VALUES (NULL, '$log_type', NOW(), '$log_size', '$log_msg', '$log_target', '$user_id')";

return $query;
}
// BBCodes
function bbtext($text){
   
   $text=str_replace('[br]','<br />',$text);
   $text=str_replace("\r",'<br />',$text);

   $text=str_replace('[left]','<div align="left">',$text);
   $text=str_replace('[/left]','</div>',$text);
   $text=str_replace('[right]','<div align="right">',$text);
   $text=str_replace('[/right]','</div>',$text);
   $text=str_replace('[center]','<div align="center">',$text);
   $text=str_replace('[/center]','</div>',$text);
   $text=str_replace('[justify]','<div align="justify">',$text);
   $text=str_replace('[/justify]','</div>',$text);

   $text=str_replace('[b]','<strong>',$text);
   $text=str_replace('[/b]','</strong>',$text);
   $text=str_replace('[i]','<i>',$text);
   $text=str_replace('[/i]','</i>',$text);

   $text=str_replace("[title]","<h1>",$text);
   $text=str_replace("[/title]","</h1>",$text);
   $text=str_replace("[subtitle]","<h2>",$text);
   $text=str_replace("[/subtitle]","</h2>",$text);
   $text=str_replace("[small]","<small>",$text);
   $text=str_replace("[/small]","</small>",$text);

   $text=str_replace('[color=','<span style="color: ',$text);
   $text=str_replace('#]',';" >', $text);
   $text=str_replace('[/color]','</span>',$text);
   
   $text=str_replace('[url]','<a href="',$text);
   $text=str_replace('[/url]','" target="_blank">LINK</a>',$text);

   $text=str_replace('[media]','<embed src="',$text);
   $text=str_replace('[/media]','" autoplay="true" loop="true">',$text);

   $text=str_replace('[BR]','<br />',$text);

   $text=str_replace('[LEFT]','<div align="left">',$text);
   $text=str_replace('[/LEFT]','</div>',$text);
   $text=str_replace('[RIGHT]','<div align="right">',$text);
   $text=str_replace('[/RIGHT]','</div>',$text);
   $text=str_replace('[CENTER]','<div align="center">',$text);
   $text=str_replace('[/CENTER]','</div>',$text);
   $text=str_replace('[JUSTIFY]','<div align="justify">',$text);
   $text=str_replace('[/JUSTIFY]','</div>',$text);

   $text=str_replace('[B]','<strong>',$text);
   $text=str_replace('[/B]','</strong>',$text);
   $text=str_replace('[I]','<i>',$text);
   $text=str_replace('[/I]','</i>',$text);
   $text=str_replace('[IMG]','<img src="',$text);
   $text=str_replace('[/IMG]','" border="0">',$text);

   $text=str_replace('[TITLE]','<h1>',$text);
   $text=str_replace('[/TITLE]','</h1>',$text);
   $text=str_replace('[SUBTITLE]','<h2>',$text);
   $text=str_replace('[/SUBTITLE]','</h2>',$text);
   $text=str_replace('[SMALL]','<small>',$text);
   $text=str_replace('[/SMALL]','</small>',$text);
   
   $text=str_replace('[COLOR=','<span style="color: ',$text);
   $text=str_replace('#]',';" >', $text);
   $text=str_replace('[/COLOR]','</span>',$text);
   
   $text=str_replace('[URL]','<a href="',$text);
   $text=str_replace('[/URL]','" target="_blank">LINK</a>',$text);

   $text=str_replace('[MEDIA]','<embed src="',$text);
   $text=str_replace('[/MEDIA]','" autoplay="true" loop="true">',$text);

return $text;
}
?>